public class GetIntersectionNode {
    //找公共节点
    public Node getIntersectionNode(Node headA, Node headB) {
        if(headA==null||headB==null){
            return null;
        }
        //1.求两个链表的长度
        Node pl = headA;
        Node ps = headB;
        int lenA = size(headA);
        int lenB = size(headB);
        int len = lenA-lenB;
        if(len<0){
            pl = headB;
            ps = headA;
            len = lenB -lenA;
        }
        //2.让长链表先走长度差,在一起走直到遇到公共节点
        while(len!=0){
            pl = pl.next;
            len--;
        }
        while(pl!=ps){
            pl = pl.next;
            ps = ps.next;
        }
        if(pl == null && ps == null){
            return null;
        }
        return pl;

    }
    public int size(Node head) {
        Node cur = head;
        int num = 0;
        while(cur!=null){
            num++;
            cur = cur.next;
        }
        return num;
    }
}
